package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 石小俊
 */
// 如果使用RestController代替原有的Controller
// 表示自动为该类中的所有方法添加@ResponseBody注解
// 即:所有方法不再返回视图,而是直接返回数据
// 特例:如果返回值是ModelAndView则还是表示返回视图与模型
@RestController
@RequestMapping
public class RequestController {

    @RequestMapping(value = "/f1", produces = "text/html;charset=utf-8")
    public String f1() {
        System.out.println("RequestController.f1");
        return "<h1>这是f1方法</h1>";
    }

    @RequestMapping(value = {"/f2", "/test", "/aaa"}, produces = "text/html;charset=utf-8")
    public String f2() {
        System.out.println("RequestController.f2");
        return "<h1>这是f2方法</h1>";
    }

    @RequestMapping("/f3/*")
    public String f3() {
        return "f3";
    }

    @RequestMapping("/f4/**")
    public String f4() {
        return "f4";
    }

    @RequestMapping("/f5/?")
    public String f5() {
        return "f5";
    }

    @RequestMapping("/f6/{name}")
    public String f6(@PathVariable String name) {
        System.out.println("name:" + name);
        return "<h1>f6</h1>";
    }

    @RequestMapping("/f7/{username}/{password}")
    public String f7(@PathVariable("username") String name, @PathVariable String password) {
        System.out.println("name:" + name + ",password:" + password);
        return "<h1>f7</h1>";
    }

    @RequestMapping("/f8/{id:\\d+}")
    public String f8(@PathVariable Integer id) {
        System.out.println("id:" + id);
        return "<h1>f8</h1>";
    }

    @RequestMapping(value = "/f9", method = RequestMethod.GET)
    public String f9() {
        return "<h1>f9</h1>";
    }

    //    @RequestMapping(value = "/f10",method = RequestMethod.POST)
    @PostMapping("/f10")
    public String f10() {
        return "<h1>f10</h1>";
    }

}
